<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [
    Vue.prototype.$vFN.Mixins.Base,
    Vue.prototype.$vFN.Mixins.Edit,
    Vue.prototype.$vFN.Mixins.List,
  ],

  data() {
    return {
      appWindow: window,
      that: this, //解决过滤器拿不到data数据的问题

      apiUrl: {
        list: "mall-site-portal/member-level/list",
      },

      levelList: [],
    };
  },
  methods: {
    init() {
      // 数据源 标签
      this.levelList = this.checkedLevelList; //从edit 传来
      console.error("checkedLevelList", this.levelList);

      // 请求等级列表
      this.mixinList_getTable();
      this.mixinEdit_editVisible = true;
    },

    btnClick(rowObj) {
      console.error("rowObj", rowObj);
      if (!this.isSelected(rowObj.row.id)) {
        this.levelList.push(rowObj.row.id);
      } else {
        this.levelList.splice(rowObj.$index, 1);
      }

      this.onSuccess(this.levelList);
      this.mixinEdit_editVisible = false;
    },

    // 批量选择
    batchChecked() {
      if (this.mixinList_selectTableData.length == 0) {
        this.$vFN.Tools.messageError("至少选择一个等级");
        return;
      }

      this.mixinList_selectTableData.forEach((item) => {
        console.log("item", item);

        if (!this.isSelected(item.id)) {
          this.levelList.push(item.id);
        }
      });
      console.log("this.levelList", this.levelList);
      this.onSuccess(this.levelList);
      this.mixinEdit_editVisible = false;
    },

    // 批量取消
    batchCancel() {
      if (this.mixinList_selectTableData.length == 0) {
        this.$vFN.Tools.messageError("至少选择一个等级");
        return;
      }

      let index = "";
      this.mixinList_selectTableData.forEach((item) => {
        console.log("item.id", item.id);

        index = this.levelList.indexOf(item.id);
        this.levelList.splice(index, 1);
      });
      this.onSuccess(this.levelList);
      this.mixinEdit_editVisible = false;
    },

    // 成功回调
    onSuccess() {},

    // 判断是否选择
    isSelected(id) {
      let _list = {};
      this.levelList.forEach((item, arrIndex) => {
        _list["key" + item] = true;
      });
      // console.error(id, _list["key" + id], _list, this.levelList);
      return _list["key" + id];
    },
  },
  mounted() {
    this.init();
  },
  filters: {},
};
</script>
